var queingAlarm = 0;
function alarm(str){
	var htmlStr = "<div class='ui-widget'><div class='ui-state-highlight ui-corner-bottom' style='margin:2px; padding: .7em .7em;'>"; 
	htmlStr += "<p><span class='ui-icon ui-icon-info' style='float: left; margin-right: .3em;'></span>";
	htmlStr += "<strong>"+str+"</strong></p></div></div>";
	$("#alarmLayer").html(htmlStr).hide();
	$("#alarmLayer").slideDown(200);
	queingAlarm++;
	setTimeout('closeAlarm()',2300);
}

function closeAlarm(){
	if(--queingAlarm==0){
		$("#alarmLayer").slideUp(500);
	}
}

function checkForm(){
	if(!$("#email").val()){
		alarm('이메일을 입력하세요');
		$("#email").focus();
		return false;
	}
	if($("#email").val().indexOf("@") < 1 || $("#email").val().indexOf(".") < 1){
		alarm('이메일을 정확히 입력하세요');
		$("#email").focus();
		return false;
	}
	if(!$("#password").val()){
		alarm('비밀번호를 입력하세요');
		$("#password").focus();
		return false;
	}
	return true;
}

function checkRegForm(){
	if(!$("#reg_email").val()){
		alarm('이메일을 입력하세요');
		$("#reg_email").focus();
		return false;
	}
	if($("#reg_email").val().indexOf("@") < 1 || $("#reg_email").val().indexOf(".") < 1){
		alarm('이메일을 정확히 입력하세요');
		$("#reg_email").focus();
		return false;
	}
	
	if(!$("#reg_password").val()){
		alarm('비밀번호를 입력하세요');
		$("#reg_password").focus();
		return false;
	}
	
	if(!$("#reg_password_confirm").val() || $("#reg_password").val() != $("#reg_password_confirm").val()){
		alarm('입력하신 비밀번호는 일치해야합니다.');
		$("#reg_password_confirm").focus();
		return false;
	}
	
	if(!$("#reg_nick").val()){
		alarm('사용하실 닉네임을 입력하세요.');
		$("#reg_nick").focus();
		return false;
	}
	
	$("#btnRegMember").attr("disabled","disabled");
	//없앨땐 	$("#btnRegMember").attr("disabled","");
	
	return true;
}

function checkRegContentForm(){
	if(!$.trim($("#content_input").val())){
		$("#content_input").val("");
		alarm('내용을 입력하세요.');
		$("#content_input").focus();
		return false;
	}
	$("#btnRegContent").attr("disabled","disabled");
	
	return true;
}

function checkUpdateMember(){
	if(!$("#nick").val()){
		alarm('사용하실 닉네임을 입력하세요.');
		$("#nick").focus();
		return false;
	}
	$("#btnUpdateMember").attr("disabled","disabled");
	//없앨땐 	$("#btnUpdateMember").attr("disabled","");
	return true;
}

function regMember(){
	$(".contentSideItems").slideUp(300);
	$("#contentRegMember").fadeIn(500);
	$("#reg_email").focus();
}
function getRegMemResult(result){
	jsonObj = JSON.parse(result, function (key, value) {
	    var type;
	    if (value && typeof value === 'object') {
	        type = value.type;
	        if (typeof type === 'string' && typeof window[type] === 'function') {
	            return new (window[type])(value);
	        }
	    }
	    return value;
	});
	$("#btnRegMember").attr("disabled","");
	
	alarm(jsonObj.ERROR_MSG);
	
	if(jsonObj.RESULT=="success"){
		$(".contentSideItems").slideDown(300);
		$("#contentRegMember").load("jsp/regMemberForm.jsp").hide();
		$("#email").focus();
	}
}

function getUpdateMemResult(result){
	jsonObj = JSON.parse(result, function (key, value) {
	    var type;
	    if (value && typeof value === 'object') {
	        type = value.type;
	        if (typeof type === 'string' && typeof window[type] === 'function') {
	            return new (window[type])(value);
	        }
	    }
	    return value;
	});
	
	$("#btnUpdateMember").attr("disabled","");
	
	alarm(jsonObj.ERROR_MSG);
	
	$("#leftSideLoginForm").load("jsp/loginForm.jsp").fadeIn(500);
}

function afterTryLogin(result){
	if(result=='success'){
		$("#leftSideLoginForm").load("jsp/loginForm.jsp").fadeIn(500);
		$(".contentSideItems").show();
		$("#contentRegMember").hide();
		alarm("로그인 성공! :) 반갑습니다~");
	}else{
		alarm("로그인에 실패하였습니다.");
	}
		
}

function lostIdPw(){
	alarm("준비중입니다. 테스트 아이디:s@s.net 비번:1234");
}

function underWorking(){
	alarm("준비중입니다.");
}

function myInfo(){
	$("#contentCommons").load("jsp/myinfoPage.jsp").hide();
	$("#contentCommons").fadeIn(500);
}

function myGroup(){
	$("#contentCommons").load("jsp/mygroupPage.jsp").hide();
	$("#contentCommons").fadeIn(500);
}

function doImgUpload(){
	var f = document.getElementById("picForm").submit();
}

function setUploadedImage(imgName){
	$("#notImageSpan").html("");
	$("#memPic").attr("src","data/"+imgName).fadeIn("fast");
	$("#leftSideLoginForm").load("jsp/loginForm.jsp").hide();
	$("#leftSideLoginForm").fadeIn(500);
}

function callRegContentForm(seq,text){
	
	$("#contentRegLayer").hide();
	$.ajax({
		   type: "POST",
		   url: "jsp/regContentForm.jsp",
		   data: "seq="+seq+"&text="+encodeURI(text),
		   success: function(msg){
			$("#contentRegLayer").html(msg);
			$("#contentRegLayer").fadeIn(500);
			getContentsList();
		}
	 });
}

function closeRegContentForm(){
	$("#contentRegLayer").fadeOut(500);
}

function regContentComplete(result){
	jsonObj = JSON.parse(result, function (key, value) {
	    var type;
	    if (value && typeof value === 'object') {
	        type = value.type;
	        if (typeof type === 'string' && typeof window[type] === 'function') {
	            return new (window[type])(value);
	        }
	    }
	    return value;
	});

	getContentsList();
	
	alarm(jsonObj.ERROR_MSG);
	
	$("#content_input").val("");
	$("#content_input").focus();
}

function getContentsList(){
	$("#listContentCurTag").hide();
	if($("#cur_tag_seq").val()){
		$.ajax({
			   type: "POST",
			   url: "jsp/contentsList.jsp",
			   data: "seq="+$("#cur_tag_seq").val(),
			   success: function(msg){
					$("#listContentCurTag").html(msg);
					$("#listContentCurTag").slideDown(500);
					$("#btnRegContent").attr("disabled","");
			}
		 });
	}
	
}

function callProfileUser(nick){
	$("#contentProfileLayer").hide();
	if(nick){
		$.ajax({
			   type: "POST",
			   url: "jsp/userProfilePage.jsp",
			   data: "nick="+encodeURI(nick),
			   success: function(msg){
					$("#contentProfileLayer").html(msg);
					$("#contentProfileLayer").slideDown(500);
			}
		 });
	}
}

function closeProfileUser(){
	$("#contentProfileLayer").fadeOut(500);
}